package model.bean;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="t_curso_externo")
public class CursoExterno {
	
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "geradorCursoExterno")
	@SequenceGenerator(name = "geradorCursoExterno", sequenceName = "sequence_curso_externo", allocationSize=1)
	@Column(name="id_curso_externo")
	private Long id;
	
	@Column(length=25)
	private String curso;
	
	@Column(length=40)
	private String instituicao;
	
	@Column(name="data_inicio")
	@Temporal(TemporalType.DATE)
	private Date   dataInicio;
	
	@Column(name="data_termino")
	@Temporal(TemporalType.DATE)
	private Date   dataTermino;
	
	@Column(name="carga_horaria",length=5)
	private Integer    cargaHoraria;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="id_curriculo",insertable=true, updatable=true)
	@Fetch(FetchMode.SELECT)
	@Cascade(CascadeType.SAVE_UPDATE)
	private Curriculo curriculo;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Curriculo getCurriculo() {
		return curriculo;
	}

	public void setCurriculo(Curriculo curriculo) {
		this.curriculo = curriculo;
	}

	public String getCurso() {
		return curso;
	}
	
	public void setCurso(String curso) {
		this.curso = curso;
	}
	
	public String getInstituicao() {
		return instituicao;
	}
	
	public void setInstituicao(String instituicao) {
		this.instituicao = instituicao;
	}
	
	public Date getDataInicio() {
		return dataInicio;
	}
	
	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}
	
	public Date getDataTermino() {
		return dataTermino;
	}
	
	public void setDataTermino(Date dataTermino) {
		this.dataTermino = dataTermino;
	}
	
	public Integer getCargaHoraria() {
		return cargaHoraria;
	}
	
	public void setCargaHoraria(Integer cargaHoraria) {
		if(cargaHoraria == 0)
			this.cargaHoraria = null;
		else
			this.cargaHoraria = cargaHoraria;
	}
}

